package cn.smbms.service;

import cn.smbms.mapper.ProviderMapper;
import cn.smbms.pojo.Provider;
import cn.smbms.util.PageBean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author Tequila
 **/
@Service
public class ProviderServiceImpl implements ProviderService {
    @Resource
    private ProviderMapper providerMapper;

    @Override
    public PageBean<Provider> findProviderList(Integer pageIndex, Integer pageSize, String queryProName, String queryProCode) {
        PageBean<Provider> page = new PageBean<>();
        page.setPageNo(pageIndex);
        page.setPageSize(pageSize);
        page.setResult(providerMapper.findProviderList(page.getStartIndex(),  pageSize,  queryProName,  queryProCode));
        page.setTotalCount(providerMapper.findCount(queryProName,  queryProCode));


        return page;
    }

    @Override
    @Transactional
    public boolean addProvider(Provider provider) {

        if (providerMapper.addProvider( provider) > 0){
            return true;
        }
        return false;
    }
}
